// pages/exercise_list/list.js
const util = require('../../../utils/util');
const storage = require('../../../utils/storage');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    category_id:'',
    category_name:'',
    list_name:''
  },

  addNewList: function(){
    let that = this;
    console.log("id: " + this.data.category_id + ",list_name:" + this.data.list_name);
    const db = wx.cloud.database();
    const _ = db.command
    db.collection('exercise_list').add({
      // data 传入需要局部更新的数据
      data: {
        category_id: that.data.category_id,
        name: that.data.list_name
      },
      success: function(res) {
        console.log("add list: " + res.data);

        wx.showToast({ // 显示Toast
          title: '添加成功',
          icon: 'success',
          duration: 1500
        });
        // 返回上一页
        wx.navigateBack({
          delta: 1,
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      category_id: options.category_id,
      category_name: options.category_name
    });

  },
})